from AgtUtil import *

logging.basicConfig(
    level=logging.DEBUG,
    format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s"
)
TEMP_PATH = 'D:\\test1\\temp\\'
APK_PATH = 'D:\\test\\apk\\1.apk'
RESULT_PATH = 'D:\\test1\\out\\'
agt = Agt(TEMP_PATH, RESULT_PATH)
agt.set_curr_apk(APK_PATH)
# agt.install_apk()
pos_dict={}
agt.atx.keep_screen()
for image in agt.curr_apk.image_dict.keys():
    logging.info(image)
    match = None
    try:
        match = agt.atx.match(image, method='sift')
    except:
        logging.error('CV error !')
    if match != None:
        threshold = match.confidence[0] * 1.0 / match.confidence[1]
    if match != None and threshold >= 0.5:
        pos_dict[image] = [match.pos,threshold]
agt.atx.free_screen()
for k,v in pos_dict.items():
    print(k,v)
# match_dict = {}
# for item in image_dict.items():
#     if item[1] != 0:
#         match_dict[item[0]] = item[1]
# logging.info('Matching done ! Positions count : %d', len(match_dict))
# pos_dict = {}
